package com.twohand.utils.Response;

import lombok.Data;

import java.io.Serializable;

@Data
public class Response implements Serializable {
    private int code;
    private String message;
    private Object data;
    private final long timestamp = System.currentTimeMillis();
    public static Object success(Object data){
        return new Response(ResponseCode.RC200.getCode(), ResponseCode.RC200.getMessage(),data);
    }
    public static Object defaultOk(ResponseCode res,Object data){
        return new Response(res.getCode(), res.getMessage(),data);
    }
    public static Object success(ResponseCode res,String message,Object data){
        return new Response(res.getCode(), message,data);
    }
    public static Response fail(String message){
        return new Response(ResponseCode.RC500.getCode(),message != null?message:ResponseCode.RC500.getMessage(),null);
    }
    public static Object customException(BaseException e){
        return new Response(e.getCode(),e.getMessage(),null);
    }
    public static Response noFound(){
        return new Response(ResponseCode.RC404.getCode(),ResponseCode.RC404.getMessage(),null);
    }
    public Response(int code, String message,Object data){
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
